<!-- 折叠列表 组件 -->
<template>
  <nav class="accWrapper">
    <div class="accTitle"
         @click="toggleList">
      <span>{{ title }}</span>
      <img src="../../assets/img/arrow_right.png"
           alt="chevron"
           :class="['accChevron', { 'open_menu': isDisplay, 'close_menu': !isDisplay }]" />
    </div>
    <ul :class="['accList', { 'maxHeight': isDisplay }]">
      <flexbox class="head">
        <flexbox-item :span="1/3">
          <ul>
            <li>体检项目名称</li>
          </ul>
        </flexbox-item>
        <flexbox-item :span="1/3">
          <ul>
            <li>检查结果</li>
          </ul>
        </flexbox-item>
        <flexbox-item :span="1/3">
          <ul>
            <li>参考值</li>
          </ul>
        </flexbox-item>
      </flexbox>
      <li class="accListItem"
          v-for="(demo, index) in list"
          :key="index">
        <flexbox>
          <flexbox-item :span="1/3">
            <ul>
              <li>{{ demo.item }}</li>
            </ul>
          </flexbox-item>
          <flexbox-item :span="1/3">
            <ul>
              <li>{{ demo.content }}</li>
            </ul>
          </flexbox-item>
          <flexbox-item :span="1/3">
            <ul>
              <li>{{ demo.hvalue }}</li>
            </ul>
          </flexbox-item>
        </flexbox>
      </li>
    </ul>
  </nav>
</template>
 
<script>
export default {
  data () {
    return {
      isDisplay: false
    }
  },
  props: {
    title: {
      type: String,
      default: ''
    },
    list: {
      type: Array,
      required: true
    }
  },
  methods: {
    toggleList () {
      this.isDisplay = !this.isDisplay
    }
  }
}
</script>
 
<style lang="less" scoped>
.head {
  border-bottom: 1px solid #aaa;
}
.accWrapper {
  display: flex;
  flex-direction: column;
}
.accTitle {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  height: 50px;
  line-height: 50px;
  font-size: 16px;
  background: hsl(0, 100%, 100%);
  text-indent: 1em;
  cursor: pointer;
}
.accChevron {
  width: 20px;
  margin-right: 15px;
}
.accList {
  border-bottom: 1px solid #aaa;
  background: #ffffff;
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 16px;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.5s ease-out;
}
.accList.maxHeight {
  max-height: 500px;
  transition: max-height 0.5s ease-in;
}
.accListItem {
  border-bottom: 1px solid #aaa;
  background-repeat: no-repeat;
  background-position: 100% 100%;
  display: flex;
  background: #ffffff;
  align-items: baseline;

  font-size: 16px;

  cursor: pointer;
}
/* chevron animation  */
@keyframes open-menu {
  to {
    transform: rotate(90deg);
  }
}
@keyframes close-menu {
  from {
    transform: rotate(90deg);
  }
  to {
    transform: rotate(0deg);
  }
}
.open_menu {
  background: #ffffff;
  animation: open-menu 0.4s ease-out forwards;
}
.thead {
  background: #ffffff;
}
.close_menu {
  animation: close-menu 0.4s ease-out forwards;
}
</style>